<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .img {
            width: 300px;
            height: 150px;
        }

        .box {
            padding-left: 150px;
        }

        span {
            width: 10px;
            height: 10px;
            border-radius: 50%;
            display: inline-block;
            margin-left: 10px;
            background: #ccc;
        }

        .active {
            background: orange !important;
        }
    </style>
</head>

<body>
    <div id="app">

    </div>


    <script src="./js/vue.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.25.0/axios.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/Mock.js/1.0.1-beta3/mock-min.js"></script>
    <script>
        // 模拟GET 无参数的接口
        // Mock.mock(请求地址, 请求方式, 返回结果)
        // Mock.mock("/api/getList", 'get', {
        //     name: "张三"
        // })

        // 模拟GET 无参数的接口 (随机生成数据)
        // Mock.mock("/api/getList", 'get', {
        //     // list|数量
        //     // list|数量-数量（范围之间）
        //     "list|10-20": [
        //         {
        //             "id|+1": 1,
        //             "name": "@cname",
        //             "title": "@ctitle",
        //             "img": "@Image(100)",
        //             "sex|0-1": 1
        //         }
        //     ]
        // })

        let arr = [
            {
                id: 1,
                title: "标题1"
            },
            {
                id: 2,
                title: "标题2"
            },
            {
                id: 3,
                title: "标题3"
            }
        ]

        // 模拟GET 有参数的接口 (用正则匹配)
        Mock.mock(RegExp('/api/getList' + ".*"), 'get', (req) => {
            console.log(req)
            let id = req.url.split('=')[1]
            return arr.filter(item => item.id === Number(id))[0]
        })


        // 生命周期 ()
        new Vue({
            el: "#app",
            data: {

            },
            created() {
                axios.get('/api/getList', {
                    params: {
                        id: 3
                    }
                }).then(res => {
                    console.log(res)
                })
            }
        })
    </script>
</body>

</html>